﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Advanced_Terrain
{
    public class ScrollingMenu
    {
        public List<String> MenuItems = new List<string>();
        public List<int> PlayerItems = new List<int>();
        public List<String> CourseItems = new List<string>();
        public CustomDiscList LocalDiscOptions;
        List<String> CurrentList;
        String SelectedItem = "Surge SS";
        int MenuID = 0;
        int ItemIndex = 0;
        SpriteFont Font;
        int FontHeight;
        SpriteBatch MySprites;
        float CurrentY = 190;
        float CurrentX = 110;
        Color MenuColor = Color.AliceBlue;
        Color SelectedColor = Color.Red;
        public Texture2D Background;
        public Boolean Visible;
        int StartIndex = 0;
        public int DiscIndex = 0;
        public void Draw()
        {

            MySprites.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            MySprites.Draw(Background, new Vector2(0, 0), Color.White);

            switch (MenuID)
            {
                case 0:
                    CurrentList = MenuItems;
                    break;
                case 1:
                    //CurrentList = PlayerItems;
                    break;
                case 2:
                    CurrentList = CourseItems;
                    break;
            }
            {
                int Counter = 0;
                foreach (String Item in CurrentList)
                {
                    if (Counter >= StartIndex && Counter <= StartIndex + 7)
                    {
                        if (SelectedItem == Item)
                        {
                            MySprites.DrawString(Font, Item, new Vector2(CurrentX - (Font.MeasureString(Item).X / 2), CurrentY), SelectedColor, 0, new Vector2(0, 0), 1.05f, SpriteEffects.None, 0);
                           // MySprites.DrawString(Font, LocalDiscOptions.DiscInfo[Counter].MaxDistance.ToString(), new Vector2((CurrentX + 40) - (Font.MeasureString(Item).X / 2), CurrentY), SelectedColor, 0, new Vector2(0, 0), 1.05f, SpriteEffects.None, 0);
                            MySprites.DrawString(Font, LocalDiscOptions.DiscInfo[PlayerItems[Counter]].MaxDistance.ToString(), new Vector2((CurrentX + 90), CurrentY), SelectedColor,0,new Vector2(0,0),1.05f,SpriteEffects.None,0);
                            MySprites.DrawString(Font, LocalDiscOptions.DiscInfo[PlayerItems[Counter]].Stability.ToString(), new Vector2((CurrentX + 150), CurrentY), SelectedColor, 0, new Vector2(0, 0), 1.05f, SpriteEffects.None, 0);
                        }
                        MySprites.DrawString(Font, Item, new Vector2(CurrentX - (Font.MeasureString(Item).X / 2), CurrentY), MenuColor);
                        MySprites.DrawString(Font, LocalDiscOptions.DiscInfo[PlayerItems[Counter]].MaxDistance.ToString(), new Vector2((CurrentX + 90), CurrentY), MenuColor);
                        MySprites.DrawString(Font, LocalDiscOptions.DiscInfo[PlayerItems[Counter]].Stability.ToString(), new Vector2((CurrentX + 150), CurrentY), MenuColor);
                        CurrentY += 3 * FontHeight;
                    }
                    Counter++;

                }
                MySprites.End();
                CurrentY = 190;
            }
        }
        public void SetSpriteBatch(GraphicsDevice device)
        {
            MySprites = new SpriteBatch(device);
        }
        public void SetFont(SpriteFont font)
        {
            Font = font;
            FontHeight = (int)Font.MeasureString("A").X;
        }
        public void Update()
        {

        }

        public void NextItem()
        {

            switch (MenuID)
            {
                case 0:
                    if (ItemIndex < MenuItems.Count - 1)
                    {
                        ItemIndex++;
                        if (ItemIndex % 8 == 0)
                            StartIndex += 8;
                    }
                    SelectedItem = MenuItems[ItemIndex];
                    
                    break;
                
            }
        }
        public void PrevItem()
        {
            if (ItemIndex > 0)
            {
                if (ItemIndex % 8 == 0)
                    StartIndex -= 8;
                ItemIndex--;

            }
            SelectedItem = MenuItems[ItemIndex];


        }
        public void SelectCurrent()
        {
            SelectedItem = MenuItems[ItemIndex];
            DiscIndex = PlayerItems[ItemIndex];
            this.Visible = false;
        }

        public void SwitchMenu(int NewMenu)
        {

            MenuID = NewMenu;
            ItemIndex = 0;
            switch (MenuID)
            {
                case 0:
                    SelectedItem = MenuItems[ItemIndex];
                    break;

            }
        }

    }
}
